
# -*- coding: utf-8 -*-

from django.forms import ModelForm, ModelChoiceField,ModelMultipleChoiceField
from wal.insumos.models import Insumo, IEntrada, ISalida
from django.contrib.admin import widgets
from django import forms

class choiceName(ModelChoiceField):
    def label_from_instance(self, obj):
        name = obj.first_name +' '+ obj.last_name
        return name
    
class choiceMultipleName(ModelMultipleChoiceField):
    def label_from_instance(self, obj):
        name = obj.first_name +' '+ obj.last_name
        return name
    
class InsumosForm(ModelForm):
    class Meta:
        model = Insumo
        
class IEntradasForm(ModelForm):
    fecha = forms.DateField(widget = widgets.AdminDateWidget(),label="* Fecha",help_text='Fecha en la que se realizó la entrada del Insumo')
    def __init__(self,*args, **kwargs):
        super(IEntradasForm, self).__init__(*args, **kwargs)
        self.fields['insumo'].queryset = Insumo.objects.order_by("nombre")
    class Meta:
        model = IEntrada
        
class ISalidasForm(ModelForm):
    fecha = forms.DateField(widget = widgets.AdminDateWidget(),label="* Fecha",help_text='Fecha en la que se realizó la salida del Insumo')
    def __init__(self,*args, **kwargs):
        super(ISalidasForm, self).__init__(*args, **kwargs)
        self.fields['insumo'].queryset = Insumo.objects.order_by("nombre")
    class Meta:
        model = ISalida

